package com.newx.common.core.enums.business;

import com.newx.common.core.exception.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * 资产账号类型
 *
 * @author LionLi
 */
@Getter
@AllArgsConstructor
public enum AssetEnum {
    /**
     * 资金账户
     */
    AMOUNT(1, "资金账户"),

    /**
     * 统一账户
     */
    TOTAL_ACCOUNT(2, "统一账户"),

    /**
     * 模拟账户
     */
    DEMO(3, "模拟账户");

    private final Integer code;
    private final String info;

    //根据code返回枚举
    public static AssetEnum getEnumByCode(Integer code) {
        for (AssetEnum assetEnum : values()) {
            if (Objects.equals(code, assetEnum.getCode())) {
                return assetEnum;
            }
        }
        throw new ServiceException("资产类型不存在");
    }

    //根据交易类型获取统一账户
    public static Integer getTotalByTradeType(Integer code) {
        if (AccountTradeTypeEnum.NORMAL.getCode().equals(code)) {
            return TOTAL_ACCOUNT.code;
        }
        if (AccountTradeTypeEnum.DEMO.getCode().equals(code)) {
            return DEMO.code;
        }
        throw new ServiceException("交易类型不存在");
    }
}
